package com.zznode.redsun.commons.dto;

import java.util.Calendar;
import java.util.Date;

import com.zznode.csp.domain.commons.util.DomainBeanUtils;
import com.zznode.redsun.commons.utils.GlobalUtils;
import com.zznode.redsun.smartcrm.model.CardCategory;
import com.zznode.redsun.smartcrm.model.PersonalInfo;
import com.zznode.redsun.smartcrm.model.Sex;

public class PersonalDto extends BaseDto {
	private Sex sex;
	private Integer age;
	private Date birthday;
	private String birthdayString;
	private String address;
	private String workUnit;
	private String cardCategoryId;
	private String cardCategoryName;
	private String cardNumber;
	private String phone1;
	private String phone2;
	private String qq;
	private String email;

	public static PersonalDto create(PersonalInfo entity) {
		PersonalDto personal = new PersonalDto();
		personal.setParentField(entity);
		personal.setSex(entity.getSex());
		personal.setBirthday(entity.getBirthday());
		personal.setBirthdayString(GlobalUtils.formartDate(personal.getBirthday()));
		personal.setAddress(entity.getAddress());
		personal.setWorkUnit(entity.getWorkUnit());
		if (null != entity.getCardCategory()) {
			personal.setCardCategoryId(entity.getCardCategory().getId());
			personal.setCardCategoryName(entity.getCardCategory().getName());
		}
		personal.setCardNumber(entity.getCardNumber());
		personal.setPhone1(entity.getPhone1());
		personal.setPhone2(entity.getPhone2());

		return personal;
	}

	public void update(PersonalInfo entity) {
		super.update(entity);
		entity.setSex(sex);
		entity.setBirthday(birthday);
		entity.setAddress(address);
		entity.setWorkUnit(workUnit);
		entity.setCardCategory(DomainBeanUtils.create(CardCategory.class, cardCategoryId));
		entity.setCardNumber(cardNumber);
		entity.setPhone1(phone1);
		entity.setPhone2(phone2);
	}

	public String getBirthdayString() {
		return birthdayString;
	}

	public void setBirthdayString(String birthdayString) {
		this.birthdayString = birthdayString;
	}

	public Sex getSex() {
		return sex;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}

	public Date getBirthday() {
		return birthday;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
		if (null != this.birthday) {
			Calendar temp = Calendar.getInstance();
			temp.setTime(this.birthday);
			this.age = Calendar.getInstance().get(Calendar.YEAR) - temp.get(Calendar.YEAR);
		}
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getWorkUnit() {
		return workUnit;
	}

	public void setWorkUnit(String workUnit) {
		this.workUnit = workUnit;
	}

	public String getCardCategoryId() {
		return cardCategoryId;
	}

	public void setCardCategoryId(String cardCategoryId) {
		this.cardCategoryId = cardCategoryId;
	}

	public String getCardCategoryName() {
		return cardCategoryName;
	}

	public void setCardCategoryName(String cardCategoryName) {
		this.cardCategoryName = cardCategoryName;
	}

	public String getCardNumber() {
		return cardNumber;
	}

	public void setCardNumber(String cardNumber) {
		this.cardNumber = cardNumber;
	}

	public String getPhone1() {
		return phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	public String getPhone2() {
		return phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

}
